//
//  SEGTarget_Message.m
//  SEGUhomeStandard
//
//  Created by 揭婧雯 on 2018/4/12.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGTarget_Message.h"
#import "SEGNewMyMessageRootViewController.h"
#import "SEGOrderMessageViewController.h"
#import "SEGSessionMessageViewController.h"
#import "SEGServiceMessageViewController.h"
#import "MessageDataBaseModel.h"
#import "SEGRedDotManager.h"
#import "SEGSubMessageModel.h"
#import "SEGRemoteNotification.h"

#import "SEGMessageLikeViewController.h"
#import "SEGWinningPublicViewController.h"

@implementation SEGTarget_Message

/**
 * 初始化消息列表
 * @author Wendy
 * @param params  跳转参数
 */
- (UIViewController*)segAction_initMessageRootViewController:(NSDictionary*)params
{
    SEGNewMyMessageRootViewController *VC = [[SEGNewMyMessageRootViewController alloc]init];
    VC.menuSid = [params valueForKey:@"menuSid"];
    VC.settingsId = [params valueForKey:@"settingsId"];
    VC.action = [params valueForKey:@"action"];
    VC.showBack = [[params allKeys]containsObject:@"showBack"] ? [[params valueForKey:@"showBack"] boolValue] : NO;
    VC.isRootVC = [[params allKeys]containsObject:@"isRootVC"] ? [[params valueForKey:@"isRootVC"] boolValue] : NO;
    return VC;
}

/**
 * 初始化到家服务聊天界面
 * @author Wendy
 * @param params  跳转参数 必传参数有groupID
 */
- (UIViewController*)segAction_initOrderMessageViewController:(NSDictionary*)params
{
    SEGOrderMessageViewController *VC = [[SEGOrderMessageViewController alloc]init];
    VC.groupID = [params valueForKey:@"groupID"];
    return VC;
}

/**
 * 初始化聊天界面
 * @author Wendy
 * @param params  跳转参数 必传参数有messageModel
 */
- (UIViewController*)segAction_initSessionMessageViewController:(NSDictionary*)params
{
    SEGSessionMessageViewController *VC = [[SEGSessionMessageViewController alloc]init];
    VC.messageModel = [params valueForKey:@"messageModel"];
    return VC;
}

/**
 * 跳转到私聊
 * @author Sam
 * @param params  私聊详情
 */
- (UIViewController*)segAction_initSessionMessageViewControllerParams:(NSDictionary*)params
{
    
    NSString *sql = [[params allKeys] containsObject:@"groupId"] ? [params valueForKey:@"groupId"] : @"";
    
    MessageModel* message = [[MessageDataBaseModel sharedDataBaseModel] getMessagesDescendingWithGroupId:sql].firstObject;
    
    if (!message) {
        message = [[MessageModel alloc] init];
        message.groupid = sql;
        message.sendUserId = [[params allKeys] containsObject:@"sendUserId"] ? [params valueForKey:@"sendUserId"] : @"";
        message.userid = kAccountUserID;
        message.title = [[params allKeys] containsObject:@"title"] ? [params valueForKey:@"title"] : @"";
        message.sender = [[params allKeys] containsObject:@"sender"] ? [params valueForKey:@"sender"] : @"";
        message.uuid = kAccountUserID;
    }
    
    SEGSessionMessageViewController *VC = [[SEGSessionMessageViewController alloc]init];
    VC.messageModel = message;
    return VC;
}

/**
 * 初始化公众号
 * @author Wendy
 * @param params  跳转参数 必传参数有messageModel
 */
- (UIViewController*)segAction_initServiceMessageViewController:(NSDictionary*)params
{
    SEGServiceBaseInfoModel *data = [SEGServiceBaseInfoModel yy_modelWithDictionary:[params valueForKey:@"serviceBaseInfoModel"]];
    SEGServiceMessageViewController *VC = [[SEGServiceMessageViewController alloc]init];
    VC.baseInfoModel = data;
    VC.groupId = [NSString stringWithFormat:@"%@|%@",data.serviceNbr,kAccountUserID];
    return VC;
}

/**
 初始化拼车聊天界面

 @param params 参数
 @return 聊天界面VC
 */
- (UIViewController *)segAction_initWayCarSessionMessageViewController:(NSDictionary *)params {
    
    NSString *fromId = params[@"fromId"] ?: @"";
    NSString *nickName = params[@"nickName"] ?: @"";
    NSString *createrID = params[@"createrID"] ?: @"";
    
    MessageModel* message = [[MessageDataBaseModel sharedDataBaseModel] getMessagesDescendingWithGroupId:fromId].lastObject;
    if (!message) {
        message = [[MessageModel alloc] init];
        message.groupid = fromId;
        message.sender = nickName;
        message.sendUserId = createrID;
        message.userid = kAccountUserID;
        message.uuid = kAccountUserID;
        
        if ([params.allKeys containsObject:@"message"]) {
            message.message = params[@"message"] ?: @"";
        }
        if ([params.allKeys containsObject:@"title"]) {
            message.title = params[@"title"] ?: @"";
        }
        if ([params.allKeys containsObject:@"isRead"]) {
            message.isRead = params[@"isRead"] ?: @"";
        }
        if ([params.allKeys containsObject:@"sendUserType"]) {
            message.sendUserType = params[@"sendUserType"] ?: @"";
        }
        if ([params.allKeys containsObject:@"contenttype"]) {
            message.contenttype = params[@"contenttype"] ?: @"";
        }
        if ([params[@"createTime"] boolValue]) {
            message.createTime = [SEGUtils stringDateByFormatString:@"yyyy-MM-dd HH:mm" withDate:[NSDate date]];
        }
        if ([params[@"communityId"] boolValue]) {
            message.communityId = kAccountCommunityID;
        }
    }
    
    if ([params[@"needSave"] boolValue]) {
        //保存消息到本地
        [[MessageDataBaseModel sharedDataBaseModel] saveMessageWithModel:message];
    }
    
    SEGSessionMessageViewController *vc = [[SEGSessionMessageViewController alloc]init];
    vc.messageModel = message;
    vc.title = nickName;
    return vc;
}

/**
 初始化老活动的聊天界面

 @param params 参数
 @return 聊天VC
 */
- (UIViewController *)segAction_initOldActivitySessionMessageViewController:(NSDictionary *)params {
    NSString *fromId = params[@"fromId"] ?: @"";
    NSString *title = params[@"title"] ?: @"";
    NSString *sender = params[@"sender"] ?: @"";
    NSString *sendUserId = params[@"sendUserId"] ?: @"";
    
    MessageModel* message = [[MessageDataBaseModel sharedDataBaseModel] getMessagesDescendingWithGroupId:fromId].firstObject;
    if (!message) {
        message = [[MessageModel alloc] init];
        message.groupid = fromId;
        message.title = title;
        message.sender = sender;
        message.sendUserId = sendUserId;
        message.userid = kAccountUserID;
        message.uuid = kAccountUserID;
    }
    
    SEGSessionMessageViewController *vc = [[SEGSessionMessageViewController alloc]init];
    vc.messageModel = message;
    vc.title = title;
    vc.hidesBottomBarWhenPushed = YES;
    return vc;
}


/**
 获取messageVC Class

 @param params 参数
 @return class
 */
-(Class)segAction_getMessageViewControllerClass:(NSDictionary *)params {
    return [SEGOrderMessageViewController class];
}
- (void)segAction_initForDidRegisterForRemoteNotificationsWithDeviceToken:(NSDictionary *)params{
    
    [[SEGRemoteNotification sharedManager] segDidRegisterForRemoteNotificationsWithDeviceToken:[params valueForKey:@"deviceToken"]];
}

- (void)segAction_initForDidReceiveRemoteNotification:(NSDictionary *)params{
    [[SEGRemoteNotification sharedManager] segDidReceiveRemoteNotification:params];
}

- (void)segAction_initJpushWithOptions:(NSDictionary *)params{
    [[SEGRemoteNotification sharedManager] initJpushWithOptions:params];
}

/**
 * 根据消息跳转到对应界面
 * @author Wendy
 */
-(void)segAction_pushToViewControllerWithRemoteNotification:(NSDictionary*)params{
    [[SEGRemoteNotification sharedManager] pushToViewControllerWithRemoteNotification:params];
}

/**
 * 提交极光推送token
 * @author Wendy
 */
-(void)segAction_submitJpushToken:(NSDictionary*)params{
    [[SEGRemoteNotification sharedManager] seg_submitJpushToken:params];
}

/**
 * 获取极光推送要设置的tag
 * @author Wendy
 */
-(void)segAction_requestGetPushTag:(NSDictionary*)params{
    [[SEGRemoteNotification sharedManager] requestGetPushTag];
}


/**
 * 保存菜单父子关系
 */
- (void)segAction_saveMenuList:(NSDictionary*)params{
    
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"array"] && [[params valueForKey:@"array"] isKindOfClass:[NSArray class]] &&
            [[params allKeys] containsObject:@"parentsSid"] && [[params valueForKey:@"parentsSid"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager saveMenuListWithArray:[params valueForKey:@"array"] parentsSid:[params valueForKey:@"parentsSid"]];
        }
    }
}

#pragma mark - 红点ID相关方法
// 获取现有的红点settingsId数组
- (NSMutableArray *)segAction_getCurrentSettingIdsArray:(NSDictionary*)params{
    return [SEGRedDotManager getCurrentSettingIdsArray];
}

/**
 * 获取红点的Type和Rescode对应关系字典
 * @return Type和Rescode对应关系字典
 */
- (NSDictionary *)segAction_getRedDotTypeAndRescodeDict:(NSDictionary*)params{
    return [SEGRedDotManager getRedDotTypeAndRescodeDict];
}


/**
 * 保存红点的Type对应的菜单ID
 *  @param params 推送或透传消息的type
 */
- (void)segAction_saveRedDotWithType:(NSDictionary*)params{
    
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"type"] && [[params valueForKey:@"type"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager saveRedDotWithType:[params valueForKey:@"type"]];
        }
    }
    
}

/**
 *  删除Type对应的本地红点信息
 *  @param params 推送或透传消息的type
 */
- (void)segAction_deleteRedDotWithType:(NSDictionary*)params{
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"type"] && [[params valueForKey:@"type"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager deleteRedDotWithType:[params valueForKey:@"type"]];
        }
    }
}


/**
 * 删除菜单ID对应的本地红点信息
 * @param params 菜单的settingsId
 */
- (void)segAction_deleteRedDotWithId:(NSDictionary*)params{
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"idString"] && [[params valueForKey:@"idString"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager deleteRedDotWithId:[params valueForKey:@"idString"]];
        }
    }
}

#pragma mark - 物业服务消息serviceId数组相关方法
/**
 * 获取所有物业服务的消息类型数组
 * @return 物业服务的消息类型数组
 */
- (NSArray *)segAction_getServiceTypeArray:(NSDictionary*)params
{
    return [SEGRedDotManager getServiceTypeArray];
}

/**
 *  获取现有的物业服务消息serviceId数组
 */
- (NSMutableArray *)segAction_getMyServiceIdArray:(NSDictionary*)params{
    return [SEGRedDotManager getMyServiceIdArray];
}

/**
 *  保存物业服务消息的serviceId
 *  @param params 推送或透传消息的serviceId
 */
- (void)segAction_saveMyServiceId:(NSDictionary*)params{
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"serviceId"] && [[params valueForKey:@"serviceId"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager saveMyServiceId:[params valueForKey:@"serviceId"]];
        }
    }
}

/**
 *  删除物业服务消息的serviceId
 *  @param params 推送或透传消息的serviceId
 */
- (void)segAction_deleteMyServiceId:(NSDictionary*)params{
    if (params && [params isKindOfClass:[NSDictionary class]]) {
        if ([[params allKeys] containsObject:@"serviceId"] && [[params valueForKey:@"serviceId"] isKindOfClass:[NSString class]]) {
            [SEGRedDotManager deleteMyServiceId:[params valueForKey:@"serviceId"]];
        }
    }
}

/**
 根据消息类型获取的对应界面 (依据type, 统一处理消息中心跳转页面)

 @param params 消息体
 */
- (void)segAction_pushToViewControllerWithMessageType:(NSDictionary *)params {
    MessageModel *msgModel;
    UINavigationController *nav;
    if ([params containsObjectForKey:@"model"]) msgModel = params[@"model"];
    if ([params containsObjectForKey:@"nav"]) nav = params[@"nav"];
    
    if ([msgModel.groupid hasPrefix:kMessageGroupLikePre] || [msgModel.groupid hasPrefix:kMessageGroupCommentPre]) { //点赞 回复
        SEGMessageLikeViewController *likeCtl = [[SEGMessageLikeViewController alloc] init];
        likeCtl.groupId = msgModel.groupid;
        if ([msgModel.groupid hasPrefix:kMessageGroupLikePre]) {
            likeCtl.title = @"赞";
        } else {
            likeCtl.title = @"回复";
        }
        likeCtl.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:likeCtl animated:YES];
        
    } else if ([msgModel.type isEqualToString:@"101800"] || [msgModel.type isEqualToString:@"100310"] || [msgModel.type isEqualToString:@"100410"]) { //聊天室 私信 ---
        SEGSessionMessageViewController *sessionMessageCtl = [[SEGSessionMessageViewController alloc] init];
        sessionMessageCtl.messageModel = msgModel;
        sessionMessageCtl.title = msgModel.sender; //标题为聊天的对象
        sessionMessageCtl.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:sessionMessageCtl animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeHomeService]) { //到家服务  ---
        SEGOrderMessageViewController *OrderDetail = [[SEGOrderMessageViewController alloc] init];
        OrderDetail.groupID = msgModel.groupid;
        OrderDetail.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:OrderDetail animated:YES];
        
    } else if ([msgModel.type isEqualToString:@"100320"]) { //闲置会话窗口  ---
        SEGSessionMessageViewController *sessionMessageCtl = [[SEGSessionMessageViewController alloc] init];
        sessionMessageCtl.messageModel = msgModel;
        sessionMessageCtl.title = msgModel.sender; //标题为聊天的对象
        sessionMessageCtl.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:sessionMessageCtl animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeActivity]) { //邻里活动 ---
        NSDictionary *params = @{@"serviceId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initOtherCreateActivityDetailViewController:params];
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypePictorial]) { //画报详情 ---
        NSDictionary *params = @{@"pictorialId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initPGCDeteailViewController:params];
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypePictorialPrize]) { //话题活动中奖通知
        NSDictionary *params = @{@"objId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initTopicDetailViewController:params];
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeUserFeedbackReply]) { //用户反馈回复
        NSDictionary *params = @{@"sugId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initFeedbackDetailViewController:params];
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:SEGIntegralCode.signup] || [msgModel.type isEqualToString:SEGIntegralCode_LEVEL_DOWNGRADE]) { //注册\降级 跳转到积分的帮助中心
        NSDictionary *params = @{@"linkURL":kIntegarlHelpCenter};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
        vc.title = @"帮助中心";
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:SEGIntegralCode_PUSH_TYPE_TELEPHONE_FARE]) { //跳转到积分的兑换记录
        NSDictionary *params = @{@"linkURL":kIntegarlExchangeRecord};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeShareGift]) { //跳转到话费充值 turnTip
        UIViewController *vc = [[SEGUhomeMediator sharedInstance]seg_initPhoneRechargeViewController:@{@"turnTip":msgModel.turnTip}];
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeInvitationSuccess]) { //分享有礼邀请成功一名邻居 跳转到邀请记录
        UIViewController *vc = [[SEGUhomeMediator sharedInstance]seg_initInviteRecordViewController:nil];
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeNotice]) { // 处理外部链接
        if (msgModel.submsg && msgModel.submsg.length > 0) {
            // 解析JSON
            NSDictionary *subMsgDic = [NSJSONSerialization JSONObjectWithData:[msgModel.submsg dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
            if (subMsgDic) {
                SEGSubMessageModel *subMsgModel = [SEGSubMessageModel initWithDictionary:subMsgDic];
                NSDictionary *params = @{@"linkURL" : subMsgModel.url};
                UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
                [nav pushViewController:vc animated:YES];
            }
        }
        
    } else if ([msgModel.type isEqualToString:kMessageTypeWinningPublicActivity]) { //中奖公告type 活动
        SEGWinningPublicViewController *viewController = [[SEGWinningPublicViewController alloc] init];
        viewController.publicType = SEGWinningPublicType_Activity;
        viewController.noticeId = msgModel.objectid;
        [nav pushViewController:viewController animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeWinningPublicTopic]) { //中奖公告type 话题
        SEGWinningPublicViewController *viewController = [[SEGWinningPublicViewController alloc] init];
        viewController.publicType = SEGWinningPublicType_Topic;
        viewController.noticeId = msgModel.objectid;
        [nav pushViewController:viewController animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeWinningPublicIntegral]) { //中奖公告type 积分商城
        SEGWinningPublicViewController *viewController = [[SEGWinningPublicViewController alloc] init];
        viewController.publicType = SEGWinningPublicType_Integral;
        viewController.noticeId = msgModel.objectid;
        [nav pushViewController:viewController animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeOffLineActivityReview]) { //线下活动审核信息
        if ([msgModel.turnTip isEqualToString:@"2"]) { //审核通过 跳邀请函
            NSDictionary *params = @{@"actId":msgModel.objectid};
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initActivityInvitationViewController:params];
            [nav pushViewController:vc animated:YES];
        } else if ([msgModel.turnTip isEqualToString:@"3"]) {
            if ([msgModel.turnType isEqualToString:@"1"] || [msgModel.turnType isEqualToString:@"2"]) { //审核不通过，跳活动详情
                NSDictionary *params = @{@"actId":msgModel.objectid,@"nav":nav};
                [[SEGUhomeMediator sharedInstance] seg_goToActivityManageDetailViewController:params];
            }
        }
        
    } else if ([msgModel.type isEqualToString:kMessageTypeTopic]) { //话题
        NSDictionary *params = @{@"objId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initTopicDetailViewController:params];
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeIntegral]) { //积分商城
        NSDictionary *var = @{@"linkURL":kIntegarlShop};
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:var];
        [nav pushViewController:VC animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeINVITENEIGHBOR]) { //邀请邻居
        UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initInviteViewController:nil];
        [nav pushViewController:VC animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeCUSTOM]) { //自定义
        if (msgModel.turnType && msgModel.turnType.length > 0) {
            NSDictionary *var = @{@"linkURL":msgModel.turnType};
            UIViewController *VC = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:var];
            [nav pushViewController:VC animated:YES];
        }
        
    } else if ([msgModel.type isEqualToString:kMessageTypeActivityDetail]) { //活动详情
        NSDictionary *params = @{@"actId":msgModel.objectid,@"nav":nav};
        [[SEGUhomeMediator sharedInstance] seg_goToActivityManageDetailViewController:params];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeNews]) { //社区资讯
        NSString *linkURL = kWebCommunityInfo(msgModel.objectid);
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:msgModel.title, @"pictorialTitle", linkURL, @"pictorialUrl", msgModel.objectid, @"newsId", nil];
        NSDictionary *params = @{
                                 @"linkURL" : linkURL,
                                 @"dict":dict,
                                 @"webType" : [NSString stringWithFormat:@"%lu",(unsigned long)SEGEnumWebType_Information],
                                 @"delegate":self,
                                 @"objId":msgModel.objectid
                                 };
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
        vc.title = @"详情";
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeExpressCollection]) { //快递代收
        NSDictionary *params = @{@"expressID":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initExpressCollectionDetailViewController:params];
        vc.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:vc animated:YES];
    
    } else if ([msgModel.type isEqualToString:kMessageTypeService]) { //物业服务
        if (msgModel.submsg && msgModel.submsg.length > 0) {
            NSDictionary* subMsgDic = [NSJSONSerialization JSONObjectWithData:[msgModel.submsg dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
            if (subMsgDic) {
                SEGSubMessageModel *subMsgModel = [SEGSubMessageModel initWithDictionary:subMsgDic];
                NSDictionary *dict = @{@"serviceOrderId":msgModel.objectid, @"organId":subMsgModel.organId};
                NSDictionary *params = @{@"orderDict":dict};
                UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initOrderDetailController:params];
                vc.title = subMsgModel.templateName;
                vc.hidesBottomBarWhenPushed = YES;
                [nav pushViewController:vc animated:YES];
            }
        }
        
    } else if ([msgModel.type isEqualToString:kMessageTypeBill]) { //费用缴纳
        RACTupleUnpack(NSNumber *isExist, NSString *webURL) = [[SEGMenulist2Manager sharedManager] getWebBillPayURL];
        if (isExist.boolValue) {
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:@{@"linkURL":ValueToString(webURL)}];
            vc.hidesBottomBarWhenPushed = YES;
            [nav pushViewController:vc animated:YES];
        } else {
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initBillListViewController:nil];
            vc.hidesBottomBarWhenPushed = YES;
            [nav pushViewController:vc animated:YES];
        }
    } else if ([msgModel.type isEqualToString:kMessageTypeQuestionnaire]) { //新问卷详情
        NSDictionary *params = @{@"linkURL" : kNewSurvey(msgModel.objectid)};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
        [nav pushViewController:vc animated:YES];

    } else if ([msgModel.type isEqualToString:kMessageTypeUserCheck]) { //用户审核 跳转到成员管理
        //跳转时取objectid（房屋id）、turnTip（房屋名称）、turnType（用户类型）
        NSDictionary *params = @{@"houseId" : msgModel.objectid, @"houseName" : msgModel.turnTip, @"userType" : msgModel.turnType};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initHouseUserListViewController:params];
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeCheckMonthCard]||
               [msgModel.type isEqualToString:kMessageTypeMonthCardActiveRemind]||
               [msgModel.type isEqualToString:kMessageTypeMonthCardExpireRemind]||
               [msgModel.type isEqualToString:kMessageTypeAddCar]) { //四种车场消息类型 跳转web
        /*
         kMessageTypeCheckMonthCard @"B_PUSH_TYPE_CHARING_YKSH" //月卡审核通知
         kMessageTypeMonthCardActiveRemind @"B_PUSH_TYPE_CARD_ACTIVE_REMIND"//月卡激活提醒
         kMessageTypeMonthCardExpireRemind @"B_PUSH_TYPE_CARD_EXPIRE_REMIND" //月卡到期提醒
         kMessageTypeAddCar @"B_PUSH_TYPE_CHARING_ADD_CAR"//新增车辆提醒
         */
        if (msgModel.submsg && msgModel.submsg.length > 0) {
            //解析JSON
            NSDictionary* subMsgDic = [NSJSONSerialization JSONObjectWithData:[msgModel.submsg dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
            if (subMsgDic) {
                SEGSubMessageModel *subMsgModel = [SEGSubMessageModel initWithDictionary:subMsgDic];
                NSDictionary *params = @{@"linkURL" : [NSString stringWithFormat:@"%@/%@",kClientRootURL,subMsgModel.url]};
                UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
                [nav pushViewController:vc animated:YES];
            }
        }
    } else if ([msgModel.type isEqualToString:kMessageTypeHouseRentalAndSale]||[msgModel.type isEqualToString:kMessageTypeCarRentalAndSale]) { //房屋租售 或者车位租售
        //seg_initMineHouseListViewController
        NSDictionary *params = @{};
        if ([msgModel.type isEqualToString:kMessageTypeCarRentalAndSale]) {
            params = @{@"selectIndex":@"1"};
        }
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMineHouseListViewController:params];
        [nav pushViewController:vc animated:YES];
        
    } else if ([msgModel.type isEqualToString:kMessageTypeOwnerAuth]) { // 住户审核
        NSDictionary *params = @{@"relId":msgModel.objectid};
        UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initHouseholdReviewViewController:params];
        [nav pushViewController:vc animated:YES];
    }
 
}

/// 用户登录积分成长值
- (void)segAction_requestLoginIntegralGrowth:(NSDictionary *)params{
    [[SEGRemoteNotification sharedManager] seg_requestLoginIntegralGrowth];
}

/// 用户注册积分成长值
- (void)segAction_requestSignUpIntegralGrowth:(NSDictionary *)params{
    [[SEGRemoteNotification sharedManager] seg_requestSignUpIntegralGrowth];
}

@end
